package org.jackysoft.query;

import java.io.Serializable;

import jodd.util.StringUtil;


/**
 * 代表查询条件
 **/
public class QueryField implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3380674943538301028L;
	private String name;
	private CompareRelation inOpr = CompareRelation.等于;
	private String value;
	private LogicRelation outOpr = LogicRelation.并且;
	private boolean noOutOpr = false; 
    private String prefix = "a.";
	
    public QueryField() {
		super();		
	}

	/**
     *带参构造
     *@param name 名
     *@param inOpr 内关系
     *@param value 值
     *@param outOpr 外关系
     *@param noOutOpr 是否有外关系
     *
     **/

	public QueryField(String name, CompareRelation inOpr, String value,
			LogicRelation outOpr, boolean noOutOpr) {
		super();
		this.name = name;
		this.inOpr = inOpr;
		this.value = value;
		this.outOpr = outOpr;
		this.noOutOpr = noOutOpr;
	}




	public String getName() {
		return name;
	}




	public void setName(String name) {
		this.name = name;
	}




	public CompareRelation getInOpr() {
		return inOpr;
	}




	public void setInOpr(CompareRelation inOpr) {
		this.inOpr = inOpr;
	}




	public String getValue() {
		return value;
	}




	public void setValue(String value) {
		this.value = StringUtil.trimLeft(StringUtil.trimRight(value));
	}




	public LogicRelation getOutOpr() {
		return outOpr;
	}




	public void setOutOpr(LogicRelation outOpr) {
		this.outOpr = outOpr;
	}




	public boolean isNoOutOpr() {
		return noOutOpr;
	}




	public void setNoOutOpr(boolean noOutOpr) {
		this.noOutOpr = noOutOpr;
	}




	@Override
	public String toString(){
		if(this.inOpr==null)this.inOpr = CompareRelation.等于;
		if(CompareRelation.类似于.equals(this.inOpr))
			return " "+this.name+" "+this.inOpr+" '%"+this.value+"%' "+(this.noOutOpr?"":this.outOpr);
		
		if("false".equalsIgnoreCase(this.value) || "true".equalsIgnoreCase(this.value))
			return " "+this.name+" is  "+this.value+"  "+(this.noOutOpr?"":this.outOpr);
		
		return " "+this.name+" "+this.inOpr+" '"+this.value+"' "+(this.noOutOpr?"":this.outOpr);
	}




	/**
	 *查询对象前缀<br/>
	 *可理解为表的别名
	 **/
	public String getPrefix() {
		return prefix;
	}




	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
}
